﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MarginTrading.Entity;
using MarginTrading.Common;
using MarginTrading.Services;

namespace MarginTrading.Forms
{
    public partial class PortfolioTable : Form
    {
        public PortfolioTable()
        {
            InitializeComponent();
        }

        private void PortfolioTable_Load(object sender, EventArgs e)
        {
            try
            {
	            DataTable portfolioTable = PortfolioServices.GetPortfolioCollectionDataTable();
	            dataGridView.DataSource = portfolioTable;
	
	            //labelSelDate.Text = DateTime.Today.ToLongDateString();
	            dataGridView.Width = Size.Width - 40;
	            dataGridView.Height = Size.Height - 140;
	
	            //dataGridViewUsers.Columns[0].Width = (dataGridViewUsers.Width * 30) / 100;
	            //dataGridViewUsers.Columns[1].Width = (dataGridViewUsers.Width * 30) / 100;
	            //dataGridViewUsers.Columns[2].Width = (dataGridViewUsers.Width * 40) / 100;
	
	            //System.Drawing.Size size = new System.Drawing.Size();
	            //size.Height = dataGridViewUsers.Height + 100;
	            //size.Width = 20;
	            //this.MinimumSize = size;
	
	            AutoCompleteStringCollection data = new AutoCompleteStringCollection();
	
	            ClientCollection clientCollection = ClientService.GetClientCollection();
	
	            for (int iI = 0; iI < clientCollection.Count; iI++)
	            {
	                data.Add(clientCollection[iI].Code);
	            }
	
	            textBoxClientCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
	            textBoxClientCode.AutoCompleteSource = AutoCompleteSource.CustomSource;
	            textBoxClientCode.AutoCompleteCustomSource = data;
	
	            SecurityCollection securityCollection = SecurityServices.GetSecurityCollection();
	
	            String sAnyOption = "Any";
	            comboBoxSymbol.Items.Add(sAnyOption);
	            comboBoxSymbol.SelectedItem = sAnyOption;
	            for (int iI = 0; iI < securityCollection.Count; iI++)
	            {
	                comboBoxSymbol.Items.Add(securityCollection[iI].Symbol);
	            }
            }
            catch (System.Exception ex)
            {
            	
            }

            WindowState = FormWindowState.Maximized;
        }

        private void PortfolioTable_SizeChanged(object sender, EventArgs e)
        {
            dataGridView.Height = Size.Height - 140;
            dataGridView.Width = Size.Width - 40;
        }

        private void buttonGO_Click(object sender, EventArgs e)
        {
            buttonGO.Focus();
            try
            {
	            DataTable portfolioTable = PortfolioServices.GetPortfolioCollectionDataTableByCodeAndSymbol(textBoxClientCode.Text, comboBoxSymbol.Text);
	            dataGridView.DataSource = portfolioTable;
	            dataGridView.Refresh();
            }
            catch (System.Exception ex)
            {
            	
            }
            textBoxClientCode.Focus();
        }

        private void toolStripButtonAdd_Click(object sender, EventArgs e)
        {

        }
    }
}
